#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int romanToInt(string s) {
        unordered_map<char, int> hash = {
            {'I', 1},
            {'V', 5},
            {'X', 10},
            {'L', 50},
            {'C', 100},
            {'D', 500},
            {'M', 1000}
        };
        int sum = 0;
        for (int i = 0; i < s.size(); i++)
        {
            if (i + 1 < s.size() && hash[s[i]] < hash[s[i + 1]])
                sum -= hash[s[i]];
            else
                sum += hash[s[i]];
        }
        return sum;
    }
};